#include "widget.h"
#include "ui_widget.h"
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    adb = new QProcess(this);
    connect(adb, &QProcess::finished, this, &Widget::cmdFinished);
    connect(adb, &QProcess::errorOccurred, this, &Widget::cmdError);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    adb->startCommand("platform-tools/adb exec-out screencap -p");
}

void Widget::cmdFinished(int code)
{
    qDebug() << code;
    QPixmap pixmap;
    pixmap.loadFromData(adb->readAll());
    ui->label->setPixmap(pixmap.scaled(ui->label->size(), Qt::KeepAspectRatio));
}

void Widget::cmdError(QProcess::ProcessError error)
{
    qDebug() << error;
}
